<!--
 * @Author: lwHao
 * @Date: 2020-10-27 17:26:38
 * @LastEditors: lwHao
 * @LastEditTime: 2020-10-29 19:39:48
-->
<template>
  <Layout>
    <!-- Page Header -->
    <header class="masthead"  :style="{
      backgroundImage: $page.general.cover.url ? `url('http://localhost:1337${$page.general.cover.url}')` : `url('/img/home-bg.jpg')`
      }">
      <div class="overlay"></div>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto">
            <div class="site-heading">
              <h1>{{$page.general.title}}</h1>
              <span class="subheading">{{$page.general.subTitle}}</span>
            </div>
          </div>
        </div>
      </div>
    </header>

    <!-- Main Content -->
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-10 mx-auto">
          
          <div class="post-preview" v-for="edge in $page.posts.edges" :key="edge.node.id">
            <g-link :to="`/post/${edge.node.id}`">
              <h2 class="post-title">{{edge.node.title}}</h2>
            </g-link>
            <p class="post-meta">
              Posted by
              <a href="#">{{edge.node.author.firstname}}{{edge.node.author.lastname}}</a>
              on {{edge.node.created_at}}
            </p>
            <p>
              <g-link :to="`/tag/${tag.id}`" v-for="tag in edge.node.tags" :key="tag.id">{{tag.title}}</g-link>
            </p>
            <hr />
          </div>
          <Pager :info="$page.posts.pageInfo"></Pager>
        </div>
      </div>
    </div>
  </Layout>
</template>

<page-query>
query ($page: Int){
  posts: allStrapiPost (perPage: 2, page: $page) @paginate {
    edges {
      node {
        id
        title
        author {
          id
          firstname
          lastname
        }
        tags {
          id
          title
        }
        created_at
      }
    }
    pageInfo {
      totalPages
      currentPage
    }
  }
  general: strapiGeneral(id: 1) {
    title
    subTitle
    cover{
      url
    }
  }
}
</page-query>
<script>
import {Pager} from 'gridsome'
export default {
  name: 'HomePage',
  components: { Pager },
  metaInfo: {
    title: 'Hello, world!'
  }
}
</script>

<style>
</style>
